<link rel="stylesheet" href="../static/layui/lib/jq-module/zyupload/zyupload-1.0.0.min.css" media="all">

<style>
    .layui-table-col-special .layui-table-cell{
        height : auto;
        overflow : visible;
        text-overflow : inherit;
    }

</style>
<div class="layuimini-container layuimini-page-anim">
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加</button>
        </div>
    </script>
    <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    <!--除 download_data 外， lay-event中的事件未实现-->
    <script type="text/html" id="currentTableBar">
        <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete_file">删除</a>
    </script>
</div>

<script src="../static/layui/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../static/layui/lib/jq-module/zyupload/zyupload-1.0.0.min.js" charset="utf-8"></script>
<script>
    layui.use(['table'], function () {
        var $ = layui.jquery,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/api/list?type=1',
            toolbar: '#toolbarDemo',
            defaultToolbar: [],
            cols: [[
                {field: 'data', width: 500, title: '寄存码', align: "center"},
                {field: 'ctime', width: 500, title: '添加时间', sort: true, align: "center"},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [15, 30, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });


     table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加黑名单',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    // btn: ["add_btn"],
                    shadeClose: true,
                    area: ['50%', '50%'],
                    content: '../static/layui/page/menu_child/block_list/add_block_list.html',
                    end: function(){
                        layui.miniAdmin.success('添加成功');
                        layui.table.reload('currentTableId');
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            <!--监听 delete 按钮 操作-->
            if (obj.event == 'delete_file'){
                layer.confirm('确认删除？',{
                    title:'确认',
                    btn:['确认','取消']
                },function(){
                    var index =  $(obj.tr).attr("data-index");
                    data = layui.table.cache["currentTableId"];
                    var data_obj = data[index]["data"];
                    $.ajax({
                        type : "get",
                        url : "/api/list?type=2&data="+data_obj,
                        data : false,
                        processData : false,
                        contentType : false,
                    success : function(result){
                        if (result.success == "false") {
                            alert("删除失败！");
                            layer.closeAll('dialog');
                        }
                        else if (result.exception == "true"){
                            alert("服务器异常");
                            layer.closeAll('dialog');
                        }
                        else if (result.success == "true"){
                            layer.msg("已删除数据！");
                            layui.table.reload('currentTableId');
                        }
                    }
                })
		});
            }
        });
    });


</script>